home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 277_01.zip / TEKDECOD.C < prev    next >
Text File  |  1993-04-01  |  5KB  |  245 lines

  1. /*
  2.  *    tekdecode.c - converts Tek4014 picture files 
  3.  *    copyright 1988 Ronald Florence 
  4.  *
  5.  *    decoding algorithm from J. Tenenbaum (2/24/87)
  6.  *    alpha mode (2/21/88)
  7.  *    linetypes (5/12/88)
  8.  *    increment mode (5/23/88)
  9.  *    corrected algorithm (6/30/88)
  10.  */
  11.  
  12. #include        <stdio.h>
  13. #include    "tek4.h"
  14.  
  15. #define US      0x1f
  16. #define RS    0x1e
  17. #define GS      0x1d
  18. #define FS      0x1c
  19. #define ESC    0x1b
  20. #define BS      0x8
  21. #define HT      0x9
  22. #define LF      0xa
  23. #define VT      0xb
  24.  
  25. #define NONE        0
  26. #define VECTOR      1
  27. #define POINT       2
  28. #define ALPHA       3
  29. #define INCREMENT    4
  30.  
  31. #define Low_Y        0x1
  32. #define Hi_bits        0x2
  33. #define Hi_mask        ~0x20
  34. #define Lox_mask    ~0x40
  35. #define Loy_mask    ~0x60
  36. #define CTRL        0
  37. #define HI        1
  38. #define LOX        2
  39. #define LOY        3
  40.  
  41. static    int    charht[4] = { 36, 40, 61, 66 },
  42.         charwd[4] = { 24, 26, 40, 44 },
  43.         cellw,            /* current width of a character cell */
  44.         chsize = 3;         /* font */
  45.  
  46.  
  47. tekdecode (infile, opt) 
  48.      FILE    *infile;
  49.      int    opt;
  50. {
  51.   register    c, mode; 
  52.   int    pts[Maxpts * 2], pn, got = 0, escape = 0, hisave, 
  53.            tx, ty, lox, loy, hix, hiy, devx, devy;
  54.   char    gstring[256], *g;
  55.  
  56.   mode = NONE;
  57.   Align(Left, Base);
  58.   Set_charsize(chsize);
  59.   while ((c = getc(infile)) != EOF) 
  60.     {
  61.       c &= 0x7f;
  62.       if (escape) 
  63.     {
  64.       parse(c);
  65.       escape = 0;
  66.       continue;
  67.     }
  68.       if (c >> 5 == CTRL)
  69.     {
  70.       if (c == '\0')    /* they pad, we strip */
  71.         continue;
  72.       if (mode == ALPHA) 
  73.         {
  74.           *g = '\0';
  75.           if (g > gstring)
  76.         Wr_str(devx, devy, gstring);
  77.           devx += (g - gstring) * cellw;
  78.           mode = NONE;
  79.         }
  80.       if (mode == INCREMENT) 
  81.         {
  82.           tx *= xm;
  83.           ty *= ym;
  84.           Increment(tx, ty);
  85.         }
  86.       if (mode == VECTOR && pn)
  87.         Vector(pn, pts);
  88.       if (mode == POINT && pn) 
  89.         Marker(pn, pts);
  90.      
  91.       switch (c) 
  92.         {
  93.         case BS:        /* cursor motions */
  94.         case HT:        /* we'll do nothing */
  95.         case VT:
  96.           break;
  97.         case GS:
  98.           mode = VECTOR;
  99.           pn = 0;
  100.           break;
  101.         case FS:
  102.           mode = POINT;
  103.           pn = 0;
  104.           break;
  105.         case US:
  106.           g = gstring;
  107.           mode = ALPHA;
  108.           break;
  109.         case ESC :
  110.           ++escape;
  111.           break;
  112.         case RS :
  113.           mode = INCREMENT;
  114.           tx = 0;
  115.           ty = 0;
  116.           break;
  117.         case LF:        /* clear bypass */
  118.           mode = NONE;
  119.           break;
  120.         }
  121.       continue;
  122.     }
  123.                 /* else not a control char */
  124.       switch (mode) 
  125.     {
  126.     case NONE:
  127.       continue;
  128.     case VECTOR:
  129.     case POINT :
  130.       switch (c >> 5)
  131.         {
  132.         case HI:
  133.           hisave = c & Hi_mask;
  134.           got |= Hi_bits;
  135.           break;
  136.         case LOY:
  137.           loy = c & Loy_mask;
  138.           got |= Low_Y;
  139.           if (got & Hi_bits) 
  140.         {
  141.           hiy = hisave;
  142.           got &= ~Hi_bits;
  143.         }
  144.           break;
  145.         case LOX:
  146.           lox = c & Lox_mask;
  147.           if (got == (Hi_bits + Low_Y))
  148.         hix = hisave;
  149.           else if (got & Hi_bits)
  150.         hiy = hisave;
  151.           got &= ~(Hi_bits | Low_Y);
  152.                 /* process the coordinates */
  153.           tx = ((hix << 5) + lox) << 2;
  154.           ty = ((hiy << 5) + loy) << 2;
  155.           devx = tx * xm + xscale;
  156.           devy = ty * ym + yscale;
  157.           pts[pn++] = devx;
  158.           pts[pn++] = devy;
  159.           if (pn > Maxpts * 2)
  160.         err("data");
  161.           break;
  162.         }
  163.       break;
  164.     case ALPHA:
  165.       *g++ = c;
  166.       break;
  167.     case INCREMENT:
  168.       switch (c) 
  169.         {
  170.         case ' ':
  171.           break;
  172.         case 'D':        /* north */
  173.           ++ty;
  174.           break;
  175.         case 'H':        /* south */
  176.           --ty;
  177.           break;
  178.         case 'A':        /* east */
  179.           ++tx;
  180.           break;
  181.         case 'B':        /* west */
  182.           --tx;
  183.           break;
  184.         case 'E':        /* northeast */
  185.           ++ty;
  186.           ++tx;
  187.           break;
  188.         case 'J':        /* southwest */
  189.           --ty;
  190.           --tx;
  191.           break;
  192.         }
  193.       break;
  194.     }
  195.     }
  196. }
  197.  
  198.  
  199. parse(inch)
  200.      int  inch;
  201. {
  202.   int    ltype = NONE;
  203.  
  204.   switch (inch) 
  205.     {
  206.     case '\f':
  207.       Clear_scr();
  208.       break;
  209.     case '`' : 
  210.     case 'e' :
  211.     case 'f' :
  212.     case 'g' :
  213.     case 'h' :
  214.     case 'm' :
  215.     case 'n' :
  216.     case 'o' :
  217.       ltype = Solid;
  218.       break;
  219.     case 'a' :
  220.     case 'i' :
  221.       ltype = Dotted;
  222.       break;
  223.     case 'b' :
  224.     case 'j' :
  225.       ltype = Dotdash;
  226.       break;
  227.     case 'c' :
  228.     case 'k' :
  229.       ltype = Shortdash;
  230.       break;
  231.     case 'd' :
  232.     case 'l' :
  233.       ltype = Longdash;
  234.       break;
  235.     case '8' :
  236.     case '9' :
  237.     case ':' :
  238.     case ';' :
  239.       Set_charsize (chsize = ';' - inch);
  240.       break;
  241.     }
  242.   if (ltype > 0)
  243.     Set_line(ltype);
  244. }
  245.